package cn.com.generaldata.os.service.indicator_evaluation.sustainable_development;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.Validate;
import org.nutz.dao.sql.Criteria;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.util.BeanMapper;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 农村恩格尔系数评估指标计算类.
 */
public class RuralEngelCoefficientCalculateService extends IndicatorEvaluationCalculateService {

	private String ruralEngel=ProvinceIndicatorConstant.RURAL_ENGEL;
//	private String[] citys=ProvinceIndicatorConstant.CITYS;
	private Integer yearBase=2001;

	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {
		IndicatorAccountVO iav=BeanMapper.map(indicatorAccountVO, IndicatorAccountVO.class);
		int num=0;
		Double now=0d;
		Double sum=0d;
		Integer inputOrAccountingMaxYear = getInputOrAccountingMaxYear(ruralEngel,indicatorAccountVO.getAreaId());
		if(inputOrAccountingMaxYear==null)
			return 0d;
		for(int i=yearBase;i<=inputOrAccountingMaxYear;i++)
		{
			iav.setYear(i);
			Double xi =getInputOrAccountingIndicatorValue(iav, iav.getYear(), ruralEngel);
			if(i==indicatorAccountVO.getYear())
				now=xi;
			if(xi!=null&&!(Double.valueOf(0).equals(xi)))
				num++;
			sum+=xi;
		}
		return (sum/num)/now;
	}
	
}
